<extend name="zh_tw:Public:base" />
<block name="title">
    <title>充值</title>
    
</block>
<block name="extendHead">
    <link rel="stylesheet" type="text/css" href="/Public/dist/Home/PayPage/recharge.css?rev=8ce4b33bb52ab09bc709ca6b5735e799">
    <link rel="stylesheet" type="text/css" href="/Public/jslib/toastr/2.1.2/toastr.min.css?rev=e36d7ff8c89b5bb6e9db66a169d59c47">
</block>
<block name="document">
    <div id="doc" class="container">
        <div id="doc-body">
            <div class="recharge-content">
                <a href="javascript:void(0);" class="type-list flex-direction-row">
                    <div class="typo-text-black-deep type-list-label">會員卡</div>
                    <div class="typo-text-black-deep hotel-name flex-1"></div>
                </a>      
                <a href="javascript:void(0);" class="type-list flex-direction-row">
                    <div class="typo-text-black-deep type-list-label">充值金額</div>
                    <div class="typo-text-black-deep typo-text-mobile flex-1">
                        <span class="input-action-trigger input-trigger-clear iconfont icon-close hidden"></span>
                        <input type="text" class="form-control input-action-clear" id="requestRecharge" maxlength="9" placeholder="請輸入充值金額">
                    </div>
                </a>         	
            </div>
            <div class="background-F5"></div> 
            <div href="/Home/PayPage/confirm?pay=1" type="button" class="pay horizontal-padding bottom-divider aliPayButton hidden">
                <div class="fixed-left-container">
                    <div class="fixed-left ali-pay">支付寶</div>
                    <div class="nowrap-content ali-checked"></div>
                </div> 
            </div>
            <div href="http://cz.uclbrt.com/Wechat/WechatLoginPage/auth.html?" type="button" class="pay horizontal-padding bottom-divider wechatPayButton hidden">
                <div class="fixed-left-container">
                    <div class="fixed-left weixin-pay">微信支付</div>
                    <div class="nowrap-content weixin-checked"></div>
                </div>   
            </div>
            <div class="horizontal-price-content hidden">充值后：{$defaultSymbol}<span></span></div>   
            <div id="doc-header" class="navbar navbar-fixed-top" >
                <div disabled="disabled" id="paybtn" data-payparams='{$signParams}' data-error='{$error}' class="col-xs-12  btn-sm btn-accent btn-raised">確認支付</div>
            </div>            
        </div>
        <include file="zh_tw:Public:Include_login" />
    </div>
    <include file="zh_tw:Public:Include_loading" is-hidden="hidden" />
</block>
<block name="extendFootJs">
    <script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="/Public/jslib/toastr/2.1.2/toastr.min.js?rev=1778e466055d4a265993e979c174c338"></script>
    <script type="text/javascript" src="/Public/dist/Home/PayPage/recharge.js?rev=b1f9585abe676cfbcafa48d285954ec1"></script>
    <script type="text/javascript">
        var getParams = getArgs();
        var currentHotel = getParams.hotel;
        var vipUserId = getParams.no;
        var vipInfoId = getParams.info;
        var color = getParams.cl; 
        var former = getParams.format;
        var signParams = $('#paybtn').data('payparams');
        var error = $('#paybtn').data('error');    
        toastr.options = {
            "newestOnTop": false,
            "timeOut": 1500,
            "extendedTimeOut": 0,
            "escapeHtml": true,
            "positionClass": "toast-bottom-center"
        };    
        if(former){
            $('#requestRecharge').val(former);           
        }
        if("{$error}"){
            toastr.error("{$error}");
        }         
        if(signParams != ''){
            wx.config({
                debug: false,
                appId: "{$signParams['appId']}",
                timestamp: "{$signParams['timestamp']}",
                nonceStr: "{$signParams['nonceStr']}",
                signature: "{$signParams['signature']}",
                jsApiList: ['chooseWXPay']
            });
            wx.ready(function() {
                // 確定支付按钮
                wx.chooseWXPay({
                    timestamp: "{$payParams['timeStamp']}",
                    nonceStr: "{$payParams['nonceStr']}",
                    package: "{$payParams['package']}",
                    signType: "{$payParams['signType']}",
                    paySign: "{$payParams['paySign']}",
                    success: function(res) {
                        window.location.href = "/Home/MemberPage/cardinfo?hotel=" + currentHotel + "&no=" + vipInfoId+ "&cl="+color+ "&user=" + vipUserId;
                    },
                    error: function() {
                        toastr.error(lang('pay.error'));
                    }
                });
            });                       
        }
        $('#paybtn').on('click',function(){
            var price = $('#requestRecharge').val();
            if(price == ''){
                toastr.error(lang('member.15'));
                return;
            }
            var ret = /^[0-9]([0-9]{0,5})(\.[\d]{1,2})?$/;
            if(!ret.test(price)){
                toastr.error(lang('member.16'));
                return;
            }          
            if(parseFloat(price) == 0){
                toastr.error(lang('member.16'));
                return;
            }    
            var href = $('#doc .check-pay').closest('.pay').attr('href');            
            if($('.aliPayButton .ali-checked').hasClass('check-pay')){
                // 支付寶支付
                params = {
                    hotel: currentHotel,
                    vipUserId: vipUserId,
                    price: price ,
                    vipInfoId:vipInfoId ,
                    color:color 
                };
                ajaxRequest('/Home/Pay/vipChargeAlipay', params, 'POST', function(data) {
                    $('body').html(data.data);
                }, function(error) {
                    toastr.error(typeof error.responseJSON === 'undefined' ? lang('tip.system') : error.responseJSON.info);
                });
            }else{
                ajaxRequest('/Home/Order/getWechatInfo', {
                    'hotelId':currentHotel
                }, 'post', function (data) {
                    var ai = data.data.ai;
                    var asc = data.data.asc;
                    window.location.href = 'http://cz.uclbrt.com/Wechat/WechatLoginPage/auth.html?type=mz&hotel=' + currentHotel + '&no=' + vipUserId  + '&cl='+color + '&info='+vipInfoId+'&format='+price + '&back=/Home/PayPage/recharge.html&pay=0&ai='+ai+'&asc='+ asc;
                }, null);                    
            }
        });      	
    </script>
</block>



